// 设置单位自动战斗指令   {"id":6,"参数":"横扫千军","类型":"人物","编号":1}
// @ts-ignore
export async function execute(client_id, message_json) {
    let characters = G.Characters.get_current_login_characters(client_id);
    //判断是否真的处于战斗中
    console.log(message_json);
    //判断是否真的处于战斗中
    if (characters["战斗开关"] !== 0) {
        // 获取战斗数据
        let fight_data = _FightDataCache.get(characters["战斗开关"]);
        // 2. 拿到目标战斗单位
        let fight_unit_number = message_json["编号"];
        let fight_unit = G.FightUtils.get_fight_unit_by_number(fight_data, fight_unit_number);
        if (fight_unit !== undefined) {
            // 3. 设置指令
            let fight_unit_db_data;
            // 3.1 拿到对应的角色或召唤兽的持久化数据
            if (fight_unit["类型"] === "角色") {
                fight_unit_db_data = _CharactersData.get(fight_unit["id"]);
            } else {
                // 召唤兽
                let uniut_characters =  _CharactersData.get(fight_unit["id"]);
                fight_unit_db_data = G.Characters.get_characters_fight_pet_data(uniut_characters);
            }
            // 3.2 更新战斗单位的战斗指令
            let param = message_json["参数"];
            // 普通攻击 防御 技能
            switch (param) {
                case "普通攻击":
                    fight_unit["自动指令"]["类型"] = "攻击";
                    fight_unit_db_data["自动指令"]["类型"] = "攻击";
                    break;
                case "防御":
                    fight_unit["自动指令"]["类型"] = "防御";
                    fight_unit_db_data["自动指令"]["类型"] = "防御";
                    break;
                default:
                    fight_unit["自动指令"]["参数"] = param;
                    fight_unit["自动指令"]["类型"] = "法术";
                    fight_unit_db_data["自动指令"]["参数"] = param;
                    fight_unit_db_data["自动指令"]["类型"] = "法术";
                    break;
            }
            // 4. 通知客户端更新指令
            let masrster_fight_unit = G.FightUtils.get_fight_unit_by_characters(fight_data, characters);
            G.FightUtils.send_auto_cmd(fight_data, masrster_fight_unit);
        }
    }
}